package sys.donto.telas;

import java.security.Principal;
import java.sql.Connection;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JDialog;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.view.JasperViewer;
import sys.donto.util.ConnectionFactory;

/**
 *
 * @author JOABB
 */
public class telaRelatorios extends javax.swing.JDialog {

    /**
     * Creates new form telaRelatorios
     */
    public telaRelatorios() {
        initComponents();
        setModal(true);
        setLocationRelativeTo(null);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        list1 = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : ((javax.persistence.Query)null).getResultList();
        jPanel4 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        btInicio = new javax.swing.JButton();
        btAjuda = new javax.swing.JButton();
        btSair1 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        btRelatorioPacientes = new javax.swing.JButton();
        btRelatorioPacientes1 = new javax.swing.JButton();
        btRelatorioPacientes2 = new javax.swing.JButton();
        btRelatorioPacientes3 = new javax.swing.JButton();
        jComboBox1 = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel4.setBackground(new java.awt.Color(153, 153, 153));

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("sysDONTO ® - Sistema de Odontologia");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel2)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel2)
                .addGap(23, 23, 23))
        );

        jPanel3.setBackground(new java.awt.Color(0, 153, 153));
        jPanel3.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel3.setPreferredSize(new java.awt.Dimension(750, 50));

        btInicio.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        btInicio.setForeground(new java.awt.Color(255, 255, 255));
        btInicio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/donto/imagens/pp-home.png"))); // NOI18N
        btInicio.setMnemonic('I');
        btInicio.setText("Início");
        btInicio.setToolTipText("Início");
        btInicio.setContentAreaFilled(false);
        btInicio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btInicioActionPerformed(evt);
            }
        });

        btAjuda.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        btAjuda.setForeground(new java.awt.Color(255, 255, 255));
        btAjuda.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/donto/imagens/pp-help.png"))); // NOI18N
        btAjuda.setMnemonic('A');
        btAjuda.setText("Ajuda");
        btAjuda.setToolTipText("Ajuda");
        btAjuda.setContentAreaFilled(false);
        btAjuda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAjudaActionPerformed(evt);
            }
        });

        btSair1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        btSair1.setForeground(new java.awt.Color(255, 255, 255));
        btSair1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/donto/imagens/cancel-button-pp.png"))); // NOI18N
        btSair1.setMnemonic('S');
        btSair1.setText("Sair");
        btSair1.setToolTipText("Sair");
        btSair1.setContentAreaFilled(false);
        btSair1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSair1ActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(255, 255, 255));
        jLabel3.setText("Relatórios");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 285, Short.MAX_VALUE)
                .addComponent(btInicio)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btAjuda)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btSair1)
                .addGap(23, 23, 23))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btInicio)
                    .addComponent(btAjuda)
                    .addComponent(btSair1))
                .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel3)
                .addContainerGap())
        );

        jPanel5.setBackground(new java.awt.Color(0, 153, 153));
        jPanel5.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel5.setPreferredSize(new java.awt.Dimension(750, 50));

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 41, Short.MAX_VALUE)
        );

        btRelatorioPacientes.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        btRelatorioPacientes.setForeground(new java.awt.Color(0, 102, 102));
        btRelatorioPacientes.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/donto/imagens/7777_32x32.png"))); // NOI18N
        btRelatorioPacientes.setMnemonic('R');
        btRelatorioPacientes.setText("Relatório de Pacientes");
        btRelatorioPacientes.setToolTipText("Relatorio de Pacientes");
        btRelatorioPacientes.setContentAreaFilled(false);
        btRelatorioPacientes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btRelatorioPacientesActionPerformed(evt);
            }
        });

        btRelatorioPacientes1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        btRelatorioPacientes1.setForeground(new java.awt.Color(0, 102, 102));
        btRelatorioPacientes1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/donto/imagens/7777_32x32.png"))); // NOI18N
        btRelatorioPacientes1.setMnemonic('R');
        btRelatorioPacientes1.setText("Relatório de Pacientes");
        btRelatorioPacientes1.setToolTipText("Relatorio de Pacientes");
        btRelatorioPacientes1.setContentAreaFilled(false);
        btRelatorioPacientes1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btRelatorioPacientes1ActionPerformed(evt);
            }
        });

        btRelatorioPacientes2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        btRelatorioPacientes2.setForeground(new java.awt.Color(0, 102, 102));
        btRelatorioPacientes2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/donto/imagens/7777_32x32.png"))); // NOI18N
        btRelatorioPacientes2.setMnemonic('R');
        btRelatorioPacientes2.setText("Relatório de Pacientes");
        btRelatorioPacientes2.setToolTipText("Relatorio de Pacientes");
        btRelatorioPacientes2.setContentAreaFilled(false);
        btRelatorioPacientes2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btRelatorioPacientes2ActionPerformed(evt);
            }
        });

        btRelatorioPacientes3.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        btRelatorioPacientes3.setForeground(new java.awt.Color(0, 102, 102));
        btRelatorioPacientes3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/donto/imagens/7777_32x32.png"))); // NOI18N
        btRelatorioPacientes3.setMnemonic('R');
        btRelatorioPacientes3.setText("Relatório de Pacientes");
        btRelatorioPacientes3.setToolTipText("Relatorio de Pacientes");
        btRelatorioPacientes3.setContentAreaFilled(false);
        btRelatorioPacientes3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btRelatorioPacientes3ActionPerformed(evt);
            }
        });

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Selecione o Relatório", "Paciente", "Dentista", "Usuário", "Serviço" }));
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(btRelatorioPacientes, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(37, 37, 37)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 330, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(btRelatorioPacientes2, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btRelatorioPacientes3, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(20, 20, 20)
                    .addComponent(btRelatorioPacientes1, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(480, Short.MAX_VALUE)))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(79, 79, 79)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btRelatorioPacientes)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btRelatorioPacientes2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btRelatorioPacientes3)
                .addContainerGap(37, Short.MAX_VALUE))
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(30, 30, 30)
                    .addComponent(btRelatorioPacientes1)
                    .addContainerGap(175, Short.MAX_VALUE)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 740, Short.MAX_VALUE)
            .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, 740, Short.MAX_VALUE)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btInicioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btInicioActionPerformed
        dispose();        // TODO add your handling code here:
    }//GEN-LAST:event_btInicioActionPerformed

    private void btAjudaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAjudaActionPerformed
        telaAjuda ta = new telaAjuda();
        ta.setVisible(true);        // TODO add your handling code here:
    }//GEN-LAST:event_btAjudaActionPerformed

    private void btSair1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSair1ActionPerformed
        dispose();
    }//GEN-LAST:event_btSair1ActionPerformed

    private void btRelatorioPacientesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btRelatorioPacientesActionPerformed
      JasperReport pathjrxml;
      HashMap parametros = new HashMap();
      String sql = "", texto = "";
      
        Connection connection = new ConnectionFactory().getConnection();
      
      try{
          JDialog viewer = new JDialog(new javax.swing.JFrame(),"Visualização do Relatorio");
          viewer.setSize(1000, 600);
          viewer.setLocationRelativeTo(null);
          viewer.setModal(true);
          pathjrxml = JasperCompileManager.compileReport("src/relatorios/relatorioPacientes.jrxml");
          JasperPrint printReport = JasperFillManager.fillReport(pathjrxml, parametros, connection);
          JasperViewer jv = new JasperViewer(printReport, false);
          viewer.getContentPane().add(jv.getContentPane());
          viewer.setVisible(true);
          
          
      }catch(JRException ex){
          Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
      }
    }//GEN-LAST:event_btRelatorioPacientesActionPerformed

    private void btRelatorioPacientes1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btRelatorioPacientes1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btRelatorioPacientes1ActionPerformed

    private void btRelatorioPacientes2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btRelatorioPacientes2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btRelatorioPacientes2ActionPerformed

    private void btRelatorioPacientes3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btRelatorioPacientes3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btRelatorioPacientes3ActionPerformed

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBox1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(telaRelatorios.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(telaRelatorios.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(telaRelatorios.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(telaRelatorios.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new telaRelatorios().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btAjuda;
    private javax.swing.JButton btInicio;
    private javax.swing.JButton btRelatorioPacientes;
    private javax.swing.JButton btRelatorioPacientes1;
    private javax.swing.JButton btRelatorioPacientes2;
    private javax.swing.JButton btRelatorioPacientes3;
    private javax.swing.JButton btSair1;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private java.util.List list1;
    // End of variables declaration//GEN-END:variables
}
